<template>
  <!-- 合并目标地址 合并预览 -->
  <div>
    <el-alert
      class="alert-success"
      v-show="showAlert"
      title="合并成功"
      type="success"
      description="请到“已确认模块查看”"
      close
      show-icon
    ></el-alert>
    <el-dialog
      :visible.sync="visible"
      :close-on-click-modal="false"
      width="90%"
      class="addr-merge-win"
      :before-close="onOk"
    >
      <div class="top">
        <div class="topleft">
          <img :src="successPng" alt="successPng" />
          <span>已选中</span>
        </div>
        <div class="topright" v-if="addrInfo">
          <div>{{addrInfo.detailaddr}}</div>
          <div>经纬度：{{addrInfo.point[0]}},{{addrInfo.point[1]}}</div>
        </div>
      </div>
      <div class="center">
        <div>还有其他目标地址转换后也对应此标准地址：</div>
        <el-table :data="tableData" @selection-change="rightHandleSelectionChange" border stripe>
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="target_address" label="目标地址" show-overflow-tooltip></el-table-column>
          <el-table-column prop="obj_number" label="对象编号"></el-table-column>
          <el-table-column prop="obj_name" label="对象名称"></el-table-column>
          <el-table-column prop="source_address" label="原地址" show-overflow-tooltip></el-table-column>
          <el-table-column prop="details" label="详情" show-overflow-tooltip></el-table-column>
        </el-table>
        <div style="padding: 12px 0;display:flex;align-items: center;">
          <img style="width:12px;height:12px;" :src="gth" alt="warning" />
          <div style="color:#F56F00;margin-left:5px;font-size:12px;">是否将上述目标地址合并到当前目标地址？</div>
        </div>
      </div>
      <div class="bottom">
        <el-button size="mini" class="bottombtn" type="primary" @click="mergeConfirm()">一键合并</el-button>
        <el-button size="mini" class="bottombtn" @click="onOk()">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import successPng from "@/icons/success.png";
import gth from "@/icons/gth.svg";
import { addOperationLog } from '@/utils/index'

export default {
  props: {
    visible: Boolean,
    onOk: Function,
    confirmSubmit: Function,
    showAlert: Boolean,
    addrInfo: Object,
    toggleAlert: Function,
  },
  data() {
    return {
      successPng,
      gth,
      tableData: [],
      checks: [],
    };
  },
  methods: {
    rightHandleSelectionChange(val) {
      this.checks = val;
    },
    async mergeConfirm() {
      if (this.checks.length == 0) {
        this.$message.warning("请最少选择一个");
        return
      }
      const res = await this.axios.post(
        this.apis.addressDataUpdateTargetAddress,
        {
          old_target_address: this.checks.map((item) => item.target_address),
          new_target_address: this.$store.state.currentTargetAddrInfo
            .target_address,
          import_file_record_id: Number(this.$store.state.currentFileInfo.id),
        }
      );
      console.log(res, "res");
      if (res.retCode === 2000) {
        this.toggleAlert(true);
        await addOperationLog({
          title: "修改目标地址",
          content: {
            old_target_address: this.checks.map((item) => item.target_address),
            new_target_address: this.$store.state.currentTargetAddrInfo
              .target_address,
          },
        });
        setTimeout(async () => {
          this.toggleAlert(false);
          this.onOk();
        }, 2000);
      }
    },
    async getList() {
      const res = await this.axios.post(this.apis.addressDataQuery, {
        page: 1,
        limit: 10,
        standard_address: this.addrInfo.standAddr,
        import_file_record_id: this.$store.state.currentFileInfo.id,
        no_eq_target_address: this.$store.state.currentTargetAddrInfo.target_address
      });
      console.log(res, "addrMergePreWin");
      if (res.retCode === 2000) {
        this.tableData = res.rows.items;
      }
    },
  },
  mounted() {
    this.getList();
  },
};
</script>

<style lang="less">
.addr-merge-win {
  .el-dialog__title {
    font-size: 14px;
    font-weight: 600;
  }
  .el-dialog__header {
    border-bottom: #ececec 1px solid;
    padding: 0;
  }

  .el-dialog__body {
    padding: 40px;
  }
  .top {
    width: 100%;
    background: #f1f9fe;
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    display: flex;
    justify-content: flex-start;
    padding: 8px 20px;
    box-sizing: border-box;
    .topleft {
      display: flex;
      flex-direction: column;
      align-items: center;
      img {
        width: 24px;
        height: 24px;
      }
      span {
        color: #1ea363;
        font-size: 12px;
      }
    }
    .topright {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      margin-left: 20px;
      & > div:nth-child(1) {
        font-size: 12px;
        font-weight: bold;
      }
      & > div:nth-child(2) {
        margin-top: 4px;
        font-style: 10px;
        color: #999;
      }
    }
  }
  .center {
    & > div:nth-child(1) {
      padding: 10px 0;
      font-size: 12px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 600;
    }
    .el-table__header-wrapper .el-table__cell {
      padding: 5px 0;
      font-size: 12px;
    }
    .el-table__body-wrapper .el-table__cell {
      padding: 5px 0;
      font-size: 10px;
    }
    th.el-table__cell {
      background-color: rgba(245, 247, 250, 1);
    }
  }
  .bottom {
    display: flex;
    justify-content: center;
    margin-top: 100px;
  }
}
.alert-success {
  z-index: 90000;
  .el-alert__title {
    color: #444 !important;
  }
  .el-alert__description {
    color: #999 !important;
  }

  width: 280px;
  position: fixed;
  top: 50px;
  z-index: 2010;
  left: 50%;
  transform: translateX(-50%);
}
</style>
